<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Operation extends CI_Controller {
	
	
	public $user_data=array();
	
	function __construct()
     {
	     parent::__construct();

		//不登陆的不让访问
		if (!$this->session->userdata('uadmin_in')){
			
			redirect('admin/home');
			
			exit();
		}
		$this->lang->load('info',$this->config->item("language"));
		$this->user_data["uadmin_name"] = $this->session->userdata('uadmin_name');
		$this->user_data["uadmin_userid"] = $this->session->userdata('uadmin_userid');
		$this->user_data["uadmin_account"] = $this->session->userdata('uadmin_account');

     }
     
	 //登陆页面
	public function index()
	{
		
     	$this->load->view("admin/login");
     
	}
	
	//处理后台登陆
	public function Customer()
	{
		$data=array();
		$data["title"]="order_manage";
		$data["bookdate1"]=date('Y-m-d');
		
		$this->load->view("admin/operation/customer",$data);
	}
	
	//客户查询
	public function querycustomer()
	{
		$data=array();
		
		$this->load->model("User_model");
		
		$data["title"]	="query customer";
		$data["result"]=$this->User_model->query_customer($_POST,$this->user_data);;
		
		$this->load->view("admin/operation/querycustomer",$data);
	}
	
	//修改客户
	public function editcustomer($sAccount)
	{
		$this->lang->load('info',"english");
		$data=array();
		
		$this->load->model("User_model");
		
		$aruser=$this->User_model->get_customer($sAccount);
		
		$data["username"]	=$aruser["username"];
		$data["birthday"]	=$aruser["birthday"];
		$data["tel"]		=$aruser["tel1"];
		$data["mobilephone"]=$aruser["mobilephone"];
		$data["address"]	=$aruser["address"];
		$data["email"]		=$aruser["Email"];
		
		$data["title"]		="edit customer";
		$data["doaction"]	="admin/operation/doeditcustomer";
		$data["txuseraccount"]=$sAccount.'<input type=hidden name="useraccount" value="'.$sAccount.'" class="txd" />';
		$data["btnreg"]="save";
		$this->load->view("admin/operation/editcustomer",$data);
	}
	//新增客户
	public function addcustomer()
	{
		$this->lang->load('info',"english");
		$data=array();
		$data["title"]="add Customer";
		$data["doaction"]	="admin/operation/doaddcustomer";
		
		$data["username"]="";
		$data["birthday"]="";
		$data["tel"]="";
		$data["mobilephone"]="";
		$data["address"]="";
		$data["email"]	="";
		
		$data["txuseraccount"]='<input type=text id="txuseraccount" name="useraccount" class="txd" />';
		$data["btnreg"]="add";
		$this->load->view("admin/operation/editcustomer",$data);
	}
	//修改
	public function doeditcustomer()
	{
		$this->load->model("User_model");
     
     	$saveresult = $this->User_model->edit_customer($_POST,$this->user_data);	
     	
    		if($saveresult)
    		{
    			$url="editcustomer/".$_POST["useraccount"];
			echo "<SCRIPT LANGUAGE=\"JavaScript\">";
			echo "alert(\"save success\");";
			echo "window.location='$url';";
			echo "</SCRIPT>";  
    		}else
    		{
    			
    			echo "save fail";
    		}
	}
	
	//新增
	public function doaddcustomer()
	{
		$this->load->model("User_model");
     
     	$saveresult = $this->User_model->add_customer($_POST,$this->user_data);	
     	
    		if($saveresult)
    		{
    			$url="editcustomer/".$_POST["useraccount"];
			echo "<SCRIPT LANGUAGE=\"JavaScript\">";
			echo "alert(\"add success\");";
			echo "window.location='$url';";
			echo "</SCRIPT>";  
    		}else
    		{
    			
    			echo "save fail";
    		}
	}
	
	//私有运价管理(国内)
	public function PrivateFreight()
	{
		
		$data=array();
		$data["title"]	="Private Freight";
		$data["type"]	=$this->input->get("type");
		
		if($data["type"]=="inter")
		{
			$data["ProductType"]="I";	
		}else
		{
			$data["ProductType"]="A";	
		}
		
		
		$data["FlightDate1"]=Date("Y-m-d",time());
		$this->load->view("admin/operation/PrivateFreight",$data);


	}
	//查询私有运价(国内)
	public function queryPrivate()
	{
		$data=array();
		$this->load->model("Policy_model");
		$data["title"]="Query Private Freight";
		
		$result=$this->Policy_model->queryPolicy($_POST,$this->user_data);
		
		$data["result"]	=$result[1];
		$data["iTotalCount"]=$result[0];
		
		$this->load->view("admin/operation/queryPrivateFreight",$data);

	}
	//新增私有运价(国内)
	public function addPrivate()
	{
		$data=array();
		$data["title"]="Add Private Fare";
		
		//设置航空公司下拉菜单
	   	$airoption =lang("aircompany");
	   	$airlist['']='=='.lang("home_allairline").'==';
	   	foreach ($airoption as $airid => $airname)
	   	{
	   		$airlist[$airid]=$airid.'-'.$airname;
	   	}

	   	$data['selairline']=form_dropdown('Airline', $airlist, '','verify="M" desc="airline" style="width:164px"');
	   	
	   	//给其他属性赋值
	   	$data["RoundTrip"]="S";
	   	$data["sFromPorts"]="";
	   	$data["sDestPorts"]="";
	   	$data["groupid"]="0";
	   	
	   	$data["sPolicyDate1"]=date("Y-m-d");
	   	$data["sPolicyDate2"]=date("Y-m-d",strtotime("+1 month"));
	   	$data["sTicketDate1"]=date("Y-m-d");
	   	$data["sTicketDate2"]=date("Y-m-d",strtotime("+1 month"));
	   	
	   	
	   	$data["sFlightNumLimit1"]="0";
	   	$data["sFlightNum1"]="";
	   	$data["sweek"]="1234567";
	   	
	   	$data["sNote"]="";
	   	$data["sEnabled"]="0";
	   	$data["arClass"]=array();
	   	
		$this->load->view("admin/operation/editPrivateFreight",$data);
	}
	//保存私有运价(国内)
	public function dosavePrivateFredight()
	{
		$this->load->model("Policy_model");
     	
     	if($this->input->post("groupid")=="0")
     	{
     		$saveresult = $this->Policy_model->add_Policy($_POST,$this->user_data);
     	}else
     	{
     		$saveresult = $this->Policy_model->edit_Policy($_POST,$this->user_data);
     	}
     	
     	
    		if($saveresult)
    		{
    			if($_POST["ProductType"]=="I")
    			{
    				$url="editinterPrivate/".$saveresult["policyid"];	
    			}else
    			{
    				$url="editPrivate/".$saveresult["policyid"];	
    			}
    			
			echo "<SCRIPT LANGUAGE=\"JavaScript\">";
			echo "alert(\"save success\");";
			echo "window.location='$url';";
			echo "</SCRIPT>";  
    		}else
    		{
    			
    			echo "save fail";
    		}
	}
	//修改私有运价(国内)
	public function editPrivate($groupid=0)
	{
		$data=array();
		$data["title"]="edit Private Fare";
		
		//设置航空公司下拉菜单
	   	$airoption =lang("aircompany");
	   	$airlist['']='=='.lang("home_allairline").'==';
	   	foreach ($airoption as $airid => $airname)
	   	{
	   		$airlist[$airid]=$airid.'-'.$airname;
	   	}

	   
	   	//给其他属性赋值
	   	$this->load->model("Policy_model");
	   	
	   	$policyrs=$this->Policy_model->get_policy($groupid);
	   	$Policydetail=$policyrs->row();
	   	$PolicyClass=$policyrs->result();
	   	
	   	$data['selairline']=form_dropdown('Airline', $airlist, $Policydetail->Airline,'verify="M" desc="airline" style="width:164px"');
	   	
	   	$data["RoundTrip"]=$Policydetail->ClassType;
	   	$data["sFromPorts"]=$Policydetail->FromPorts;
	   	$data["sDestPorts"]=$Policydetail->DestPorts;
	   	$data["groupid"]=$groupid;
	   	
	   	$data["sPolicyDate1"]=date("Y-m-d",strtotime($Policydetail->SalesDate1));
	   	$data["sPolicyDate2"]=date("Y-m-d",strtotime($Policydetail->SalesDate2));
	   	$data["sTicketDate1"]=date("Y-m-d",strtotime($Policydetail->FlightDate1));
	   	$data["sTicketDate2"]=date("Y-m-d",strtotime($Policydetail->FlightDate2));
	   	
	   	if($Policydetail->FlightNum1=="")
	   	{
	   		$data["sFlightNumLimit1"]="0";
	   		$data["sFlightNum1"]="";
	   	}else if(substr($Policydetail->FlightNum1,0,1)=="!")
	   	{
	   		$data["sFlightNumLimit1"]="2";
	   		$data["sFlightNum1"]=substr($Policydetail->FlightNum1,1);
	   	}else
	   	{
	   		$data["sFlightNumLimit1"]="1";
	   		$data["sFlightNum1"]=$Policydetail->FlightNum1;
	   	}
	   	
	   	$data["sweek"]=$Policydetail->WeekDay1;
	   	$data["sNote"]=$Policydetail->Note;
	   	$data["sEnabled"]=$Policydetail->isSleep;
	   	$data["arClass"]=$PolicyClass;
		$this->load->view("admin/operation/editPrivateFreight",$data);
	}
	
	//删除私有运价
	public function deletePolicy()
	{
		$this->load->model("Policy_model");
		$this->Policy_model->delete_Policy($this->input->get("id"),$this->user_data);
		
		echo "<SCRIPT LANGUAGE=\"JavaScript\">";
		echo "alert('delete success');";
		echo "window.parent.document.getElementById('formPrivate').submit();";
		echo "</SCRIPT>";  
	}
	
	/*国际运价管理*/
	
	//新增私有运价(国内)
	public function addinterPrivate()
	{
		$data=array();
		$data["title"]="Add Internation Private Fare";
		
		//设置航空公司下拉菜单
	   	if($this->user_data["uadmin_account"]=="flyguam")
	   	{
	   		$airoption =array('5K'  =>'5K AIR');
	   	}else
	   	{
	   		$airlist['']='=='.lang("home_allairline").'==';
	   		$airoption =lang("aircompany");
	   	}
	   	
	   	
	   	foreach ($airoption as $airid => $airname)
	   	{
	   		$airlist[$airid]=$airid.'-'.$airname;
	   	}

	   	$data['selairline']=form_dropdown('Airline', $airlist, '','verify="M" desc="airline" style="width:164px"');
	   	
	   	//给其他属性赋值
	   	$data["RoundTrip"]="S";
	   	$data["sFromPorts"]="";
	   	$data["sDestPorts"]="";
	   	$data["groupid"]="0";
	   	
	   	$data["sPolicyDate1"]=date("Y-m-d");
	   	$data["sPolicyDate2"]=date("Y-m-d",strtotime("+1 month"));
	   	$data["sTicketDate1"]=date("Y-m-d");
	   	$data["sTicketDate2"]=date("Y-m-d",strtotime("+1 month"));
	   	
	   	
	   	$data["sFlightNumLimit1"]="0";
	   	$data["sFlightNum1"]="";
	   	$data["sweek"]="1234567";
	   	
	   	$data["sNote"]="";
	   	$data["sEnabled"]="0";
	   	$data["arClass"]=array();
	   	
		$this->load->view("admin/operation/editinterPrivateFreight",$data);
	}
	
	//修改私有运价(国内)
	public function editinterPrivate($groupid=0)
	{
		$data=array();
		$data["title"]="edit Internation Private Fare";
		
		//设置航空公司下拉菜单
	   	
	   	
	   	
	   	if($this->user_data["uadmin_account"]=="flyguam")
	   	{
	   		$airoption =array('5K'  =>'5K AIR');
	   	}else
	   	{
	   		$airlist['']='=='.lang("home_allairline").'==';
	   		$airoption =lang("aircompany");
	   	}
	   	
	   	foreach ($airoption as $airid => $airname)
	   	{
	   		$airlist[$airid]=$airid.'-'.$airname;
	   	}

	   
	   	//给其他属性赋值
	   	$this->load->model("Policy_model");
	   	
	   	$policyrs=$this->Policy_model->get_policy($groupid);
	   	$Policydetail=$policyrs->row();
	   	$PolicyClass=$policyrs->result();
	   	
	   	$data['selairline']=form_dropdown('Airline', $airlist, $Policydetail->Airline,'verify="M" desc="airline" style="width:164px"');
	   	
	   	$data["RoundTrip"]=$Policydetail->ClassType;
	   	$data["sFromPorts"]=$Policydetail->FromPorts;
	   	$data["sDestPorts"]=$Policydetail->DestPorts;
	   	$data["groupid"]=$groupid;
	   	
	   	$data["sPolicyDate1"]=date("Y-m-d",strtotime($Policydetail->SalesDate1));
	   	$data["sPolicyDate2"]=date("Y-m-d",strtotime($Policydetail->SalesDate2));
	   	$data["sTicketDate1"]=date("Y-m-d",strtotime($Policydetail->FlightDate1));
	   	$data["sTicketDate2"]=date("Y-m-d",strtotime($Policydetail->FlightDate2));
	   	
	   	if($Policydetail->FlightNum1=="")
	   	{
	   		$data["sFlightNumLimit1"]="0";
	   		$data["sFlightNum1"]="";
	   	}else if(substr($Policydetail->FlightNum1,0,1)=="!")
	   	{
	   		$data["sFlightNumLimit1"]="2";
	   		$data["sFlightNum1"]=substr($Policydetail->FlightNum1,1);
	   	}else
	   	{
	   		$data["sFlightNumLimit1"]="1";
	   		$data["sFlightNum1"]=$Policydetail->FlightNum1;
	   	}
	   	
	   	$data["sweek"]=$Policydetail->WeekDay1;
	   	$data["sNote"]=$Policydetail->Note;
	   	$data["sEnabled"]=$Policydetail->isSleep;
	   	$data["arClass"]=$PolicyClass;
		$this->load->view("admin/operation/editinterPrivateFreight",$data);
	}
	
	
}

/* End of file home.php */
/* Location: ./application/controllers/home.php */